private ["_selection", "_control", "_selectedIndex", "_current_mission", "_XD_display","_str","_hour","_rain","_overcast","_mindex","_matched"];

disableSerialization;

_selection = _this select 0;

_control = _selection select 0;
_selectedIndex = _selection select 1;

if (_selectedIndex == -1) exitWith {};
DM_DIALOG_MISSIONID = _selectedIndex;

_current_mission = (["available_missions",[]] call XNetGetJIP) select _selectedIndex;
diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"selection_changed.sqf","Current Mission",_current_mission];

_XD_display = uiNameSpace GetVariable "XD_MISSIONS_DIALOG";

_control = _XD_display displayCtrl 2007;
_str = _current_mission select 2;
_control ctrlSetText (_str call XfTranslate);

_control = _XD_display displayCtrl 2008;
_str = _current_mission select 3;
_control ctrlSetText (_str call XfTranslate);

_control = _XD_display displayCtrl 2009;
_str = str(_current_mission select 4);
_control ctrlSetText (_str call XfTranslate);

_hour = floor((_current_mission select 6) select 0);
_ctrl = _XD_display displayCtrl 4001;
_ctrl lbSetCurSel _hour;
DM_DIALOG_TIME = _hour;

_rain = _current_mission select 7;
_overcast = _current_mission select 8;
_ctrl = _XD_display displayCtrl 4002;
_mindex = 0;
_index = 0;
{
	_matched = false;
	if (_rain >= 0) then {
		if ((_x select 1) <= _rain) then {_matched = true;};
	};
	if ((_overcast >= 0) And _matched) then {
		_matched = false;
		if ((_x select 2) <= _overcast) then {_matched = true;};
	};
	if (_matched) then {_mindex = _index};
	_index = _index + 1;
}foreach d_mission_dlg_weather;
_ctrl lbSetCurSel _mindex;
DM_DIALOG_WEATHER = _mindex;
